#pragma once

#include "ICoreGraphic.h"
#include "ArkD3DBase.h"
#include <algorithm>
#include "CDynamicVB.h"

#define MAX_DYNAMIC_LIGHT		32

//namespace ArkGraphic
/*{*/

struct LIGHTSTATE
{
	LIGHTSTATE()
	{
		m_DynamicLightUsed = 0;
		for( int i = 0; i < MAX_DYNAMIC_LIGHT; i++ )
			m_DynamicLight[i] = new D3DLIGHT;
	}
	~LIGHTSTATE()
	{
		for( int i = 0; i < MAX_DYNAMIC_LIGHT; i++ )
			delete m_DynamicLight[i];
	}

	D3DLIGHT*				m_DynamicLight[MAX_DYNAMIC_LIGHT];
	int						m_DynamicLightUsed;
};

class CLightSystem : public ILightSystem
{
	bool					m_bMainLightEnable;
	bool					m_bDynamicLightEnable;
	D3DLIGHT				m_MainLight;

	LIGHTSTATE*				m_LightStateChain;
	LIGHTSTATE*				m_CurLightState;
	LIGHTSTATE*				m_PreLightState;

	bool                    m_bLightEnable;
	DWORD					m_Ambient;
	ARKLIGHT				m_SingleLight;

	ICoreGraphic*			m_pGraphic;

public:
	CLightSystem();
	~CLightSystem(void);

	void			Init( ICoreGraphic* pGraphic );
	void			Flip();
	void			SetLight( const VBLight& Lights );
	DWORD			GetAmbient(){ return m_Ambient; };
	void			SetSingleLight( const ARKLIGHT& SingleLight );
	const ARKLIGHT& GetSingleLight();

	virtual void	SetMainLightAsDir( const CVector3f& LightDir, DWORD Color );
	virtual void	SetMainLightAsDot( const CVector3f& Pos, float Attenuation, float Rang, DWORD Color );
	virtual void	GetMainLightDir( CVector3f& LightDir, const CVector3f& Pos );
	virtual void	EnableMainLight( bool bEnable );
	virtual void	EnableDynamicLight( bool bEnable );
	virtual void	AddDynamicLight( const CVector3f& Pos, float Attenuation, float Rang, DWORD Color );
	virtual void	SetLight( const CVector3f& Pos, BOOL bAll );
	virtual void	SetAmbient( DWORD Color );
	virtual void	SetAmbientSrcAsMaterial( bool bMaterial );
};

/*};*/